package com.seveneight.baijiesteward.ui.user.model;

import android.content.Context;
import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.seveneight.baijiesteward.bean.AnyBean;
import com.seveneight.baijiesteward.bean.BaseEntity;
import com.seveneight.baijiesteward.bean.CardBean;
import com.seveneight.baijiesteward.bean.CreditBean;
import com.seveneight.baijiesteward.http.BaseModel;
import com.seveneight.baijiesteward.http.BaseObserver;
import com.seveneight.baijiesteward.http.MyCallBack;
import com.seveneight.baijiesteward.http.RetrofitFactory;
import com.seveneight.baijiesteward.ui.user.contract.CardListContract;
import com.seveneight.baijiesteward.ui.user.contract.CreditCardListContract;

import java.util.List;

import okhttp3.RequestBody;

/**
 * Created by user1 on 2018/3/23.
 */

public class CreditCardListModel extends BaseModel implements CreditCardListContract.CreditCardListModel {

    @Override
    public void getCreditCardList(Context context, RequestBody body, MyCallBack<List<CreditBean>> myCallBack) {
        RetrofitFactory.getInstence().API().getCreditCardList(body)
                .compose((this.<BaseEntity<AnyBean>>setThread()))
                .subscribe(new BaseObserver<AnyBean>(context) {
                    @Override
                    protected void onSuccees(BaseEntity<AnyBean> t) throws Exception {
                        List<CreditBean> data = JSON.parseArray(t.getData().getCreditCardList(), CreditBean.class);
                        Log.e("xxxxxxxldb",JSON.toJSONString(t.getData()));
                        myCallBack.onSuccess(data);
                    }

                    @Override
                    protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {

                    }
                });
    }
}
